using System;
using System.Collections.Generic;
using System.Text;
using System.Runtime.Serialization;

namespace net.notdot.Attercop {
    [Serializable()]
    public class QueueNotificationMessage : Message, TcpMessage {
        public readonly int Position;
        public readonly int Slots;
        public readonly TimeSpan ETA;

        static QueueNotificationMessage() { ClientInstance.AddMessageHandler<QueueNotificationMessage>(); }

        public QueueNotificationMessage(MessageAddressing addressing, int position, int slots, TimeSpan eta) : base(addressing) {
            this.Position = position;
            this.Slots = slots;
            this.ETA = eta;
        }

        public QueueNotificationMessage(MessageAddressing addressing, int position, int slots)
            : this(addressing, position, slots, TimeSpan.MinValue) {
        }

        protected QueueNotificationMessage(MessageReader reader) : base(reader) {
            reader.BeginRegion();
            reader.ReadByte();  //Version
            this.Position = reader.ReadInt32();
            this.Slots = reader.ReadInt32();
            this.ETA = new TimeSpan(reader.ReadInt64());
            reader.EndRegion();
        }

        public override void Serialize(MessageWriter writer)
        {
            base.Serialize(writer);

            writer.BeginRegion();
            writer.Write((byte)0);  //Version
            writer.Write(this.Position);
            writer.Write(this.Slots);
            writer.Write(this.ETA.Ticks);
            writer.EndRegion();
        }
    }
}
